package com.orkun.api.converter.writer;


import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;














import com.orkun.api.converter.impl.AddressInfoModel;

//https://code.google.com/p/opencsv
import au.com.bytecode.opencsv.CSVWriter;


/**
 * CSV writer implementation for AddressInfoModel
 */
public class WriterCSV implements Writer<AddressInfoModel> {

  public void output(OutputStream os, ArrayList<AddressInfoModel> models) {
    CSVWriter writer;
    try {
      writer = new CSVWriter(new OutputStreamWriter(os), CSVWriter.DEFAULT_SEPARATOR, CSVWriter.NO_QUOTE_CHARACTER);

      // feed in your array (or convert your data to an array)
      String[] columns = AddressInfoModel.getColumns();
      writer.writeNext(columns);
      for (AddressInfoModel model : models) {
        writer.writeNext(model.toArray());
      }
      writer.close();
    } catch (IOException e) {
      System.out.println("Exception occured while writing to CSV : " + e.getMessage());
    }
  }  
}
